﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Domain.Values
{
	using System.Collections.Generic;
	using Falcon.Core.Extensions;
	using Falcon.Core.Validation;

	public class UserSearchCreate : ValueBase<UserSearchCreate>
	{
		/// <summary>
		/// Gets or sets the title.
		/// </summary>
		/// <value>The title.</value>
		public string Title
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		public string Name
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the email address.
		/// </summary>
		/// <value>The email address.</value>
		public string EmailAddress
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the host address.
		/// </summary>
		/// <value>The host address.</value>
		public string HostAddress
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the created after.
		/// </summary>
		/// <value>The created after.</value>
		public string CreatedAfter
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the created before.
		/// </summary>
		/// <value>The created before.</value>
		public string CreatedBefore
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the last visit after.
		/// </summary>
		/// <value>The last visit after.</value>
		public string LastVisitAfter
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the last visit before.
		/// </summary>
		/// <value>The last visit before.</value>
		public string LastVisitBefore
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the posts greater than.
		/// </summary>
		/// <value>The posts greater than.</value>
		public int PostsGreaterThanOrEqual
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the posts less than.
		/// </summary>
		/// <value>The posts less than.</value>
		public int PostsLessThanOrEqual
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the reputation greater than.
		/// </summary>
		/// <value>The reputation greater than.</value>
		public int ReputationGreaterThanOrEqual
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the reputation less than.
		/// </summary>
		/// <value>The reputation less than.</value>
		public int ReputationLessThanOrEqual
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether save this <see cref="UserSearchCreate"/>
		/// </summary>
		/// <value><c>true</c> if save; otherwise, <c>false</c>.</value>
		public bool Save
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the searches.
		/// </summary>
		/// <value>The searches.</value>
		public IList<UserSearch> Searches
		{
			get; 
			set;
		}

		/// <summary>
		/// Validation rules for this instance.
		/// </summary>
		/// <returns></returns>
		public override Validator<UserSearchCreate> Rules()
		{
			var rules = base.Rules();

			if (this.CreatedAfter.HasValue())
			{
				rules.Add(x => x.CreatedAfter)
					.Date(Resources.Errors.DateNotValid.Fmt(Resources.Titles.After));
			}

			if (this.CreatedBefore.HasValue())
			{
				rules.Add(x => x.CreatedBefore)
					.Date(Resources.Errors.DateNotValid.Fmt(Resources.Titles.Before));
			}

			if (this.LastVisitAfter.HasValue())
			{
				rules.Add(x => x.LastVisitAfter)
					.Date(Resources.Errors.DateNotValid.Fmt(Resources.Titles.After));
			}

			if (this.LastVisitBefore.HasValue())
			{
				rules.Add(x => x.LastVisitBefore)
					.Date(Resources.Errors.DateNotValid.Fmt(Resources.Titles.Before));
			}

			if (this.Save)
			{
				rules.Add(x => x.Title)
					.NotEmpty(Resources.Errors.Required.Fmt(Resources.Titles.Title));
			}

			return rules;
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}